package com.example.widgetcase.slice;

import com.example.widget_lib.widget.progress.horbar.SectionProBar;
import com.example.widgetcase.ResourceTable;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Slider;
import ohos.agp.utils.Color;

public class SectionProBarAblility extends BaseSlice implements Slider.ValueChangedListener {

    private SectionProBar bar1;
    private SectionProBar bar2;
    private SectionProBar bar3;

    @Override
    public int getChildUIContent() {
        return ResourceTable.Layout_section_probar;
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        bar1 = (SectionProBar) findComponentById(ResourceTable.Id_section_probar1);
        bar2 = (SectionProBar) findComponentById(ResourceTable.Id_section_probar2);
        bar3 = (SectionProBar) findComponentById(ResourceTable.Id_section_probar3);
        Slider slider1 = (Slider) findComponentById(ResourceTable.Id_slider1);
        Slider slider2 = (Slider) findComponentById(ResourceTable.Id_slider2);
        slider1.setValueChangedListener(this);
        slider2.setValueChangedListener(this);

        int sc1 = Color.rgb(15, 252, 255);
        int ec1 = Color.rgb(0, 150, 255);
        int sc2 = Color.rgb(255, 104, 83);
        int ec2 = Color.rgb(100, 122, 219);

        bar1.setProgress(0);

        bar2.setGradientBgColor(sc1, ec1);
        bar2.setGradientProColor(sc2, ec2);
        bar2.setProgress(0);

        bar3.setGradientBgColor(sc1, ec1);
        bar3.setGradientProColor(sc2, ec2);
        bar3.setProgressAnim(80f);

        Button button = (Button) findComponentById(ResourceTable.Id_button);
        button.setClickedListener(component -> bar3.setProgressAnim(80f));
    }

    @Override
    public void onProgressUpdated(Slider slider, int i, boolean b) {
        switch (slider.getId()) {
            case ResourceTable.Id_slider1:
                bar1.setProgress(slider.getProgress());
                break;
            case ResourceTable.Id_slider2:
                bar2.setProgress(slider.getProgress());
                break;
        }
    }

    @Override
    public void onTouchStart(Slider slider) {

    }

    @Override
    public void onTouchEnd(Slider slider) {

    }
}
